package com.yidu.boss.sys.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yidu.boss.sys.dao.LogMapper;

import com.yidu.boss.sys.domain.Log;
import com.yidu.boss.sys.domain.LogExample;
import com.yidu.boss.sys.service.LogService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service
public class LogServiceImpl implements LogService {

    @Resource
    private LogMapper logMapper;

    @Override
    public List<Log> selectAll() throws ParseException {
        LogExample logExample = new LogExample();
        logExample.setOrderByClause("logTime desc");
        List<Log> logs = logMapper.selectByExample(logExample);
        SimpleDateFormat Format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (Log log : logs) {

        }
        return logs;
    }

    @Override
    public boolean insertSelective(Log record) {
        int i = logMapper.insertSelective(record);
        if (i!=0) {
            return true;
        }
        return false;
    }

    @Override
    public PageInfo<Log> selectPage(Integer page, Integer limit) throws ParseException {
        PageHelper.startPage(page,limit);
        List<Log> logs =  selectAll();
        PageInfo<Log> logPageInfo = new PageInfo<>(logs);
        return logPageInfo;
    }

    @Override
    public PageInfo<Log> selectRangeDate(Date value,Date value1, Integer page, Integer limit,Log log) {
        LogExample logExample = new LogExample();
        boolean isNullUserName=!"".equals(log.getUserName())&& log.getUserName()!=null;
        boolean isNullLogId=!"".equals(log.getLogId())&& log.getLogId()!=null;
        boolean isNullMotion=!"".equals(log.getMotion())&& log.getMotion()!=null;
        //判断时间值 是否相等 如果相等取一个值 不相等 取一个范围
        if (value.getTime() == value1.getTime()) {

        }else {

        }
        PageHelper.startPage(page,limit);
        List<Log> logs =logMapper.selectByExample(logExample);
        PageInfo<Log> logPageInfo = new PageInfo<>(logs);
        return logPageInfo;
    }




}
